/**
 *reated by lqj on 17-09-29.
 */

var async = require('async');
var mtOrder = mongoose.model('mtOrder');
var toolUtil = require('../common/utils/toolUtil');


//小区大使在APp中查看自己的业绩
exports.communityAmbassadordataShowApp = function (req,callback){
    var token=req.params.token;
    var  resultArr={};
    toolUtil.getUserByToken(token, function (err, user) {
        if (err) {
            callback(err, null);
        } else {
            async.series([
                function (callbackInner1){
                        //作为下单人的成单数
                        mtOrder.count({
                            "order_user" : user._id,
                            "is_share_moderator" : false,
                        },function(err,count){
                            if(count){
                                callbackInner1(null,count);
                            }else{
                                callbackInner1(null,0);
                            }
                        })
                },function(callbackInner2){
                        //作为分享人的成单数
                        mtOrder.count({
                            "share_user" : user._id
                        },function(err,count){
                            if(count){
                                callbackInner2(null,count);
                            }else{
                                callbackInner2(null,0);
                            }
                        })
                    }
            ],function(innercallback,result){
                countResult=result[0]+result[1];
                resultArr.countResult=countResult;
                callback(null,resultArr);
            });
        }})

}